package com.cnc.dao.Impl;

import com.cnc.dao.UserDao;
import com.cnc.entity.Admin;
import com.cnc.utils.DBUtil;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    public int login(String user,String pwd) {
        int rows = 0;
        try {
            rows = (int) (long) DBUtil.getQr().query("select count(*) from admin where username=? AND password=?", new ScalarHandler(), user, pwd);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rows;
    }
    public int isHaveAdmin(String username) {
        int query = 0;
        try {
            query = (int) (long) DBUtil.getQr().query("select count(*) from admin where username=?", new ScalarHandler(), username);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return query;
    }
    public int insertAdmin(Admin a) {
        int rows = 0;
        try {
            rows = DBUtil.getQr().update("insert into admin(username,password) values(?,?)", a.getUsername(), a.getPassword());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rows;
    }
}
